using System;
using System.IO;
using Newtonsoft.Json.Linq;

namespace ThemeSwitchTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("主题切换功能完整测试");
            Console.WriteLine("==================");
            
            // 检查主题文件是否存在
            string projectPath = @"..\..\..\MouseKeyboardOperationSimulator\MouseKeyboardOperationSimulator";
            string darkThemePath = Path.Combine(projectPath, "themes", "dark_theme.json");
            string lightThemePath = Path.Combine(projectPath, "themes", "light_theme.json");
            
            Console.WriteLine($"检查暗色主题文件: {darkThemePath}");
            Console.WriteLine($"检查明亮主题文件: {lightThemePath}");
            
            if (!File.Exists(darkThemePath))
            {
                Console.WriteLine($"错误：未找到暗色主题文件 {darkThemePath}");
                //Console.WriteLine("按任意键退出...");
                //Console.ReadKey();
                return;
            }
            
            if (!File.Exists(lightThemePath))
            {
                Console.WriteLine($"错误：未找到明亮主题文件 {lightThemePath}");
                //Console.WriteLine("按任意键退出...");
                //Console.ReadKey();
                return;
            }
            
            // 测试加载和解析主题文件
            try
            {
                Console.WriteLine("\n正在测试加载和解析暗色主题文件...");
                string darkThemeContent = File.ReadAllText(darkThemePath);
                JObject darkTheme = JObject.Parse(darkThemeContent);
                Console.WriteLine($"成功加载暗色主题: {darkTheme["name"]}");
                Console.WriteLine($"主题作者: {darkTheme["author"]}");
                Console.WriteLine($"主题版本: {darkTheme["version"]}");
                
                // 检查颜色配置
                var colors = darkTheme["colors"];
                if (colors != null)
                {
                    Console.WriteLine($"找到 {colors.Count()} 种颜色定义");
                    foreach (var color in colors)
                    {
                        Console.WriteLine($"  {color.Path}: {color.First}");
                    }
                }
                
                // 检查样式配置
                var styles = darkTheme["styles"];
                if (styles != null)
                {
                    Console.WriteLine($"找到 {styles.Count()} 种样式定义");
                }
                
                Console.WriteLine("\n正在测试加载和解析明亮主题文件...");
                string lightThemeContent = File.ReadAllText(lightThemePath);
                JObject lightTheme = JObject.Parse(lightThemeContent);
                Console.WriteLine($"成功加载明亮主题: {lightTheme["name"]}");
                Console.WriteLine($"主题作者: {lightTheme["author"]}");
                Console.WriteLine($"主题版本: {lightTheme["version"]}");
                
                // 检查颜色配置
                var lightColors = lightTheme["colors"];
                if (lightColors != null)
                {
                    Console.WriteLine($"找到 {lightColors.Count()} 种颜色定义");
                }
                
                // 检查样式配置
                var lightStyles = lightTheme["styles"];
                if (lightStyles != null)
                {
                    Console.WriteLine($"找到 {lightStyles.Count()} 种样式定义");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"测试过程中出错：{ex.Message}");
                Console.WriteLine($"堆栈跟踪：{ex.StackTrace}");
                //Console.WriteLine("按任意键退出...");
                //Console.ReadKey();
                return;
            }
            
            Console.WriteLine("\n所有测试已完成！");
            Console.WriteLine("主题切换功能应该可以正常工作。");
            //Console.WriteLine("按任意键退出...");
            //Console.ReadKey();
        }
    }
}
